//
//  RBNoDataView.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/18.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "RBNoDataView.h"

@interface RBNoDataView()
@property(nonatomic, strong) UIImageView *nodataIv;
@property(nonatomic, strong) UILabel *nodataLb;
@end
@implementation RBNoDataView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    [self addSubview:self.nodataIv];
    [self addSubview:self.nodataLb];
}

#pragma mark - lazy
- (UIImageView *)nodataIv {
    if (!_nodataIv) {
        _nodataIv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tip_evaluate"]];
    }
    return _nodataIv;
}
- (UILabel *)nodataLb {
    if (!_nodataLb) {
        _nodataLb = [[UILabel alloc] init];
        _nodataLb.text = @"您的购物车是空的";
        _nodataLb.textColor = [UIColor lightGrayColor];
        _nodataLb.textAlignment = NSTextAlignmentCenter;
    }
    return _nodataLb;
}

- (void)layoutSubviews {
    [super layoutSubviews];
   
    CGFloat h = 200;
    CGFloat x = (300 - h) / 2;
    
    self.nodataIv.frame = CGRectMake(x, 30, h, h);
    
    self.nodataLb.frame = CGRectMake(x, h+30, h, 50);
}


- (void)rb_showNoDataViewInView:(UIView *)view message:(NSString *)msg placeHolder:(NSString *)img {
    self.frame = CGRectMake(0, 0, 300, 400);
    self.rb_center_x = view.rb_center_x;
    self.rb_center_y = view.rb_center_y;
    [view addSubview:self];
    
    
    // 重新显示无数据 文字 + 图片
    if (![NSString isEmptyString:msg]) {
        self.nodataLb.text = msg;
    }
    
    if (![NSString isEmptyString:img]) {
        self.nodataIv.image = [UIImage imageNamed:img];
    }
}


//- (void)rb_showNoDataViewInView:(UIView *)view {
//    self.frame = CGRectMake(0, 0, 300, 400);
//    self.rb_center_x = view.rb_center_x;
//    self.rb_center_y = view.rb_center_y;
//    [view addSubview:self];
//}

- (void)rb_hideNoDataView {
    [self removeFromSuperview];
}

- (void)dealloc {
    XJLog(@"视图被销毁");
}

@end
